package h0724;

import java.util.*;
import java.util.regex.Pattern;

/**
  * @description 数字字符串组合倒序
  * @author 不知名帅哥
  * @date 2024/7/25 0:19
  * @version 1.0
*/
public class NumericStringCombinationReverseOrder {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String[] s = sc.nextLine().split(" ");
        String res=getRes(s);
//        String res = reverseWords(sc.nextLine());
        System.out.println(res);
    }

    private static String getRes(String[] s) {
        LinkedList<String> list = new LinkedList<>();
        for (String string : s) {
            list.add(string);
        }

        //结果
        StringJoiner res = new StringJoiner(" ");
        while (!list.isEmpty()){
            String temp = list.removeLast();
            String s1 = processWord(temp);
            if (s1.isEmpty()){
               continue;
            }
            res.add(s1);
        }

        return res.toString();
    }
    private static String processWord(String word){
        //几种情况
        //1. 非数字字母字符 替换为""
        //2. -xxx- 替换成xxx
        //3. 只有-，替换为""
        //4. xxx--xxx 替换为-- 为空格
        boolean m1 = word.matches("[a-zA-Z0-9]+-[a-zA-Z]+");
        if (m1){
            return word;
        }
        boolean m2 = word.matches("[a-zA-Z]+--[a-zA-Z]+");
        if (m2){
            return word.replace("--"," ");
        }
        //3. 只有-，替换为""
//        if (word.equals("-")){
//            return "";
//        }
        //非法字符 比如@%$ 或者 --xxxx
        //1，3可以合并
        return word.replaceAll("[^a-zA-Z0-9]","");
    }
}
